package com.neuedu.second;

public class StringTestDriver {
    public static void main(String[] args) {
    test02();

    }


    /**
     * 字符串的存储
     */
    private static void test02(){
        int i = 10; // 10 就是常量
        // 定义一个字符串
        String str00 = "小明"; // 此处 创建了 1个
        String str01 = "小明"; // 创建了 1个对象（常量池中的元素不重复）
        // 如果只有下面一行代码执行的话，请问在该行代码之后在内存中创建了 2个对象
        String str10 = new String("小明"); // 创建了 2个对象
        String str11 = new String("小明"); // 创建了 3个对象

        System.out.println("str00 == str10::"+(str00 == str10));
        System.out.println("str00 == str01::"+(str00 == str01));
        System.out.println("str11 == str10::"+(str11 == str10));
        System.out.println("str00 == str11::"+(str00 == str11));
    }

    /**
     * String类常用方法：indexOf
     */
    private static void test01(){
        String str0="jkdafjlk|asdjl,kfjlk|asd,389048923,jsdffjsdkalfj9o23";
        String str1="www";
        String str2="hhhrrr";
        System.out.println("原始字符串："+str0);
        System.out.println("a的位置：："+str0.indexOf('a'));

        System.out.println("substring截取字符串：");
        System.out.println(""+str0.substring(3));
        System.out.println(""+str0.substring(str0.indexOf('a')));
        System.out.println(""+str0.substring(3,5));
        System.out.println(""+str0.substring(3,12));


        System.out.println("字符串分割：");
        String[] strs=str0.split(",");
        for (String str:strs){
            System.out.println(str);
        }

        System.out.println("字符串分割2：");
        String[] strs2=str0.split("[|]");
        for (int i=0;i<strs2.length;i++){
            System.out.println(strs2[i]);
        }

        System.out.println("索引处的 char 值");
        System.out.println(str0.charAt(0));

        System.out.println("指定索引处的字符-Unicode 代码点");
        System.out.println(str0.codePointAt(3));

        /**
         * compareTo?
         */
        System.out.println("按字典顺序比较两个字符串");
        System.out.println(str1.compareTo(str2));


        System.out.println("将指定字符串连接到此字符串的结尾");
        System.out.println(str1.concat(str2));

        System.out.println("查找指定下标的字符："+str0.indexOf(97,'b'));

        int i=str0.compareTo("zabc");
        System.out.println("compareTo：："+i);

        String newStr0=str0.replace("asd","###");
        System.out.println("Old::"+str0);
        System.out.println("New::"+newStr0);
    }
}
